from PyQt5.QtCore import QThread, pyqtSignal


class ConnectThread(QThread):
    """用于设备的连接，防止卡死界面"""
    connect_state_signal = pyqtSignal(bool)

    def __init__(self):
        super().__init__()
        self.instrument = None

    def run(self) -> None:
        if self.instrument is None:
            return
        try:
            if self.instrument.init():
                self.connect_state_signal.emit(True)
            else:
                self.connect_state_signal.emit(False)
        except Exception as e:
            print(str(e))
            self.connect_state_signal.emit(False)
            return
